<template>
  <!-- 补贴记录 -->
  <div style="overflow:scroll">
    <mt-loadmore
      :bottom-method="loadBottom"
      :bottom-all-loaded="allLoaded"
      ref="loadmore"
      :bottomDistance="bottomDistance"
    >
      <ul class="subsidy-ul m_t20">
        <li class="subsidy-item bg_colorff" v-for="item in subsidyArr">
          <div class="flex flex-pack-justify font_size32 m_b20">
            <p
              class="font-bold"
            >{{item.name.length>14?item.name.substring(0,14)+'...':item.name}}</p>
            <p class="color_fc">￥{{Number(item.balance).toFixed(2)}}</p>
          </div>
          <p class="font_size24 color_99">补贴时间:{{item.create_time | DateFomate}}</p>
        </li>
      </ul>
    </mt-loadmore>
  </div>
</template>

<script>
export default {
  data() {
    return {
      subsidyArr: [],
      pagesNum: 1, //当前页数
      maxPageNum: 0, //最大页数
      allLoaded: false, //是否宣布加载完
      bottomDistance: 120
    };
  },

  mounted() {
    this.getPageData(false);
  },

  methods: {
    //获取页面数据
    getPageData(isScroll = true) {
      if (isScroll) {
        if (this.pagesNum >= this.maxPageNum) {
          this.pagesNum = this.maxPageNum;
          this.allLoaded = true;
          this.$toast("无更多数据");
          return;
        } else {
          this.pagesNum++;
        }
      } else {
        this.pagesNum = 1;
      }
      this.$util
        .get("user/getSubsidyUserList", {
          uid: this.$store.state.userinfo.uid,
          page: this.pagesNum
        })
        .then(res => {
          this.maxPageNum = res.data.last_page;
          this.subsidyArr = res.data.data.concat(this.subsidyArr);
        });
    },
    loadBottom() {
      // 上拉加载
      this.getPageData(); // 上拉触发的分页查询
      this.$refs.loadmore.onBottomLoaded(); // 固定方法，查询完要调用一次，用于重新定位
    }
  }
};
</script>
<style lang='less' scoped>
@import url(../../assets/css/balance/subsidy.less);
</style>